//
//  CategoryBigCollectionViewCell.m
//  EveryDesigner
//
//  Created by CJX on 2016/10/31.
//  Copyright © 2016年 Shanghai DuRui Information Technology Company. All rights reserved.
//

#import "CategoryBigCollectionViewCell.h"
#import "CategorySmallCollectionViewCell.h"


#define CATEGORYSMALLCELL @"categorySmallCell"
@interface CategoryBigCollectionViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,retain)UICollectionView * smallCollectionView;

@property (nonatomic,retain)NSArray * myDataArray;

@end

@implementation CategoryBigCollectionViewCell


-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame: frame];
    if (self) {
        self.myDataArray = [NSArray array];
        [self creatCollectionView];
    }
    
    return self;
}
-(void)setDataArray:(NSMutableArray *)dataArray{
    
    _myDataArray = dataArray;
    [_smallCollectionView reloadData];
}

-(void)creatCollectionView{
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 0, 5);
    layout.itemSize = CGSizeMake((KScreenWidth-25)/3, (KScreenWidth-25)/3*1.4);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    _smallCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight*0.95-64) collectionViewLayout:layout];
    _smallCollectionView.backgroundColor = [UIColor whiteColor];
    _smallCollectionView.delegate = self;
    _smallCollectionView.dataSource = self;
    [self.contentView addSubview:_smallCollectionView];
    [_smallCollectionView registerNib:[UINib nibWithNibName:@"CategorySmallCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:CATEGORYSMALLCELL];
    
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.myDataArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CategorySmallCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CATEGORYSMALLCELL forIndexPath:indexPath];

    CategoryModel * model = self.myDataArray[indexPath.item];
    cell.model = model;
    
    return  cell;
    
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    CategoryModel * model = self.myDataArray[indexPath.item];
    
    [self.delegate letCategoryVCGoToCommodityVCWithId:model.categories_id andName:model.categories_name andParma:model.param];
}



@end
